package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.WdyHuobiTrade;
import com.ruoyi.system.service.IWdyHuobiTradeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 火币委托交易 信息操作处理
 * 
 * @author ruoyi
 * @date 2020-03-08
 */
@Controller
@RequestMapping("/system/wdyHuobiTrade")
public class WdyHuobiTradeController extends BaseController
{
    private String prefix = "system/wdyHuobiTrade";
	
	@Autowired
	private IWdyHuobiTradeService wdyHuobiTradeService;
	
	@RequiresPermissions("system:wdyHuobiTrade:view")
	@GetMapping()
	public String wdyHuobiTrade()
	{
	    return prefix + "/wdyHuobiTrade";
	}
	
	/**
	 * 查询火币委托交易列表
	 */
	@RequiresPermissions("system:wdyHuobiTrade:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WdyHuobiTrade wdyHuobiTrade)
	{
		startPage();
        List<WdyHuobiTrade> list = wdyHuobiTradeService.selectWdyHuobiTradeList(wdyHuobiTrade);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出火币委托交易列表
	 */
	@RequiresPermissions("system:wdyHuobiTrade:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WdyHuobiTrade wdyHuobiTrade)
    {
    	List<WdyHuobiTrade> list = wdyHuobiTradeService.selectWdyHuobiTradeList(wdyHuobiTrade);
        ExcelUtil<WdyHuobiTrade> util = new ExcelUtil<WdyHuobiTrade>(WdyHuobiTrade.class);
        return util.exportExcel(list, "wdyHuobiTrade");
    }
	
	/**
	 * 新增火币委托交易
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存火币委托交易
	 */
	@RequiresPermissions("system:wdyHuobiTrade:add")
	@Log(title = "火币委托交易", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WdyHuobiTrade wdyHuobiTrade)
	{
		try {
			wdyHuobiTradeService.trade(wdyHuobiTrade);
			return success();
		} catch (Exception e) {
			log.error("委托交易异常", e);
			return error(e.getMessage());
		}

	}

	/**
	 * 修改火币委托交易
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap)
	{
		WdyHuobiTrade wdyHuobiTrade = wdyHuobiTradeService.selectWdyHuobiTradeById(id);
		mmap.put("wdyHuobiTrade", wdyHuobiTrade);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存火币委托交易
	 */
	@RequiresPermissions("system:wdyHuobiTrade:edit")
	@Log(title = "火币委托交易", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WdyHuobiTrade wdyHuobiTrade)
	{		
		return toAjax(wdyHuobiTradeService.updateWdyHuobiTrade(wdyHuobiTrade));
	}
	
	/**
	 * 删除火币委托交易
	 */
	@RequiresPermissions("system:wdyHuobiTrade:remove")
	@Log(title = "火币委托交易", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wdyHuobiTradeService.deleteWdyHuobiTradeByIds(ids));
	}
	
}
